<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// Route::any('/analogin', 'User\UserController@loginAs');
// Route::get('/category', 'Main\CategoryController@index');
// Route::get('/category/{cat}', 'Main\CategoryController@show');
// Route::patch('/category', 'Main\CategoryController@store');
// Route::post('/category/{cat}', 'Main\CategoryController@update');
// Route::delete('/category/{cat}', 'Main\CategoryController@destory');
// Route::get('/test', 'Main\IndexController@test')->name('api.test');

Route::post('/register', 'User\TokenAuthController@register');
Route::get('/login', 'User\TokenAuthController@login')->name('login');
Route::post('/uc/logout', 'User\TokenAuthController@uclogout')->name('uc.logout');
Route::get('/uc/logined', 'User\TokenAuthController@logined')->name('uc.logined');

Route::group([
    'middleware' => ['tokenAuth', 'logger'],
], function() {
    # 代理调用用户中心的userinfo接口
    Route::get('/user/ucInfo', 'User\UserController@userinfo');
    Route::get('/user', 'User\UserController@currentUser');
    Route::post('/logout', 'User\TokenAuthController@logout')->name('logout');
    # 代理调用b应用的a接口
    Route::get('/call/app_b/api_a', 'Main\IndexController@api_a');
    
});


# 需要校验权限, 务必注意, 该路由组下所有路由必须设置name
Route::group([
    'middleware' => ['tokenAuth', 'logger', 'permission'],
], function() {
    Route::get('/category/list', 'Main\CategoryController@index')->name('category.list');
    Route::group([ 'namespace' => 'Api'], function($router) {
        Route::resource('channels', 'ChannelsController')->only(['index', 'store', 'show', 'update', 'destroy'])->names([
            'store' => 'channels.insert',
        ]);
    });
    
});


# 需要校验app/time/token
Route::group([
    'middleware' => 'privateApi',
], function() {
    # 被其他应用代理调用的接口
    Route::get('/proxy/test', 'Main\IndexController@test1');
});